package com.liesheng.haylou.common.recycleView;

import android.content.Context;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;


import java.util.List;

/**
 * Date:2019/11/7
 * <p>
 * Author:wuzhiguang
 * <p>
 * Description:
 */
public abstract class CommonAdapter<T,V extends ViewDataBinding> extends RecyclerView.Adapter<RecyclerViewHolder> {
    protected List<T> contentDatas;
    protected int layoutId;
    protected Context mContext;

    public CommonAdapter(Context paramContext, List<T> paramList, int layoutId) {
        this.mContext = paramContext;
        this.layoutId = layoutId;
        this.contentDatas = paramList;
    }

    public abstract void contentConvert(V binding, T t, int position);

    @Override
    public int getItemCount() {
        return this.contentDatas.size();
    }

    @Override
    public RecyclerViewHolder onCreateViewHolder(ViewGroup paramViewGroup, int paramInt) {
        V binding = DataBindingUtil.inflate(LayoutInflater.from(mContext), layoutId, null, false);
        return new RecyclerViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(RecyclerViewHolder holder, int position) {
        contentConvert((V) holder.binding, this.contentDatas.get(position), position);
    }


}
